import requests
import re

url = 'http://127.0.0.1:8000/admin/login/'
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
}
s = requests.Session()
response = s.get(url, headers=headers)
csrf = re.search(f'<input type="hidden" name="csrfmiddlewaretoken" value="(.*?)">', response.text).group(1)
print(csrf)
data = {
    'csrfmiddlewaretoken': csrf,
    'username': 'admin',
    'password': '123456',
    'next': '/admin/',
}
response = s.post(url, headers=headers, data=data)
url = 'http://127.0.0.1:8000/admin/'
response = s.get(url, headers=headers)
print(response.text)
